package com.ler.yrmall.order.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.ler.yrmall.basic.BaseEntity;
import com.ler.yrmall.order.enums.PaymentEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;

/**
 * 订单
 * @author Leron
 */
@Data
@TableName("oms_order")
@EqualsAndHashCode(callSuper = true)
public class OrderEntity extends BaseEntity<OrderEntity> {

    /**
     * 订单号
     */
    private String orderSn;

    /**
     * member_id
     */
    private Long memberId;

    /**
     * 用户名
     */
    private String memberUsername;

    /**
     * 使用的优惠券
     */
    private Long couponId;

    /**
     * 订单总额
     */
    private BigDecimal totalAmount;

    /**
     * 应付总额
     */
    private BigDecimal payAmount;

    /**
     * 运费金额
     */
    private BigDecimal freightAmount;

    /**
     * 积分抵扣金额
     */
    private BigDecimal integrationAmount;

    /**
     * 优惠券抵扣金额
     */
    private BigDecimal couponAmount;

    /**
     * 支付方式
     * @see PaymentEnum
     */
    private Integer payType;

    /**
     * 订单状态
     * @see OrderStatus
     */
    private Integer status;

    /**
     * 物流公司
     */
    private String deliveryCompany;

    /**
     * 物流单号
     */
    private String deliverySn;

    /**
     * 自动确认时间
     */
    private Integer autoConfirmDay;

    /**
     * 可以获得的积分
     */
    private Integer integration;

    /**
     * 可以获得的成长值
     */
    private Integer growth;

    /**
     * 收货人姓名
     */
    private String receiverName;

    /**
     * 收货人电话
     */
    private String receiverPhone;

    /**
     * 收货人邮编
     */
    private String receiverPostCode;

    /**
     * 省份/直辖市
     */
    private String receiverProvince;

    /**
     * 城市
     */
    private String receiverCity;

    /**
     * 区
     */
    private String receiverRegion;

    /**
     * 详细地址
     */
    private String receiverDetailAddress;


    /**
     * 下单时使用的积分
     */
    private Integer useIntegration;

    public enum OrderStatus {

        /**
         * 订单状态
         */
        NON_PAY(0,"待付款"),

        /**
         * 已付款/待发货
         */
        WAIT_DELIVER(1,"待发货"),

        DELIVERED(2,"已发货"),

        FINISH(3,"已完成"),

        CANCEL(4,"订单取消"),

        APPLY_REFUND(5,"申请退款"),

        REFUNDED(6,"退款申请通过"),

        CLOSE(7,"交易关闭");

        private final Integer code;

        private final String dict;

        OrderStatus(Integer code, String dict) {
            this.code = code;
            this.dict = dict;
        }

        public Integer getCode() {
            return code;
        }

        public String getDict() {
            return dict;
        }

        public static String translate(Integer code) {
            for (OrderStatus value : OrderStatus.values()) {
                if (value.getCode().equals(code)) {
                    return value.getDict();
                }
            }
            return "";
        }
    }

}
